<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Redis;
use App\Models\Shop;
use App\Models\ShopEnvelop;
use App\Services\TencentMap;
use App\Services\RedisService;
use App\Repos\UserRepo;
use App\Repos\ShopRepo;
use App\Repos\OrderRepo;
use Cache;
use Carbon\Carbon;
use EasyWeChat;

class IndexController extends Controller
{
    public function dashboard()
    {
        $userNum = UserRepo::count();
        $shopNum = ShopRepo::count();
        $orderNum = OrderRepo::orderCount();
        $totalAmount= OrderRepo::orderAmount();
        return view('admin.dashboard',compact('userNum','shopNum','orderNum','totalAmount'));
    }

    public function index()
    {
    	
        // $keys = Redis::keys('*');
      
        // Redis::del('fruit:shops');
        //dd(Redis::get('name'));
       // $shops_types = Redis::type('shops');
        //$shops = Redis::zrange('shops',0,-1);
        //dd($keys,$shops_types,$shops);
        //Redis::set('name', 'Taylor');
    	//$user = Redis::get('name');
    	


    	
    	// $items = Redis::georadius("fruit:shops:geo", '120.429533', '36.177618', 5000, "m", "WITHDIST", "ASC");
    	// dd($items);

        //$rs= TencentMap::coordiateToAddress('36.173867,120.427149');
        //dd($rs);
    }

    public function test()
    {
        // 获取老板顿用户
        $app = EasyWeChat::miniProgram('shop'); // 小程序
        $list = $app->user->list();  // $nextOpenId 可选
        dd($list);
       //  $tomorrow = Carbon::now()->addDays(1);          //2016-11-04 00:00:00
       // echo $tomorrow;
           $shops = Shop::get();
          // dd($shops);
        foreach ($shops as $k => $v) {
            if(!$v->lnglat) continue;
            $lng = explode(',', $v->lnglat)[0];
            $lat = explode(',', $v->lnglat)[1];
            Redis::geoadd("fruit:shops:geo", $lng, $lat, $v->id);
        }
        
           // RedisService::set('3','23233',10);

        //echo strtotime('tomorrow');die;
        // $data['money'] = 100;
        // $data['shop_id'] =1;
        // $data['recharge_id'] =1;
        // $envelops = generateEnvolpeArr($data['money']);     
        // foreach ($envelops as $key => $e) {
        //     $v['recharge_id'] = $data['recharge_id'];
        //     $v['shop_id']     = $data['shop_id'];
        //     $v['money']       = $e;
        //     $se = ShopEnvelop::create($v); 
        //     $key = 'fruit:shops:envelops:'.$data['shop_id'];
        //     $value = json_encode(['id'=>$se->id,'money'=>$e]);
        //     RedisService::lpush($key,$value);
        // }
           
    }
}
